import MySQLdb
import os

conn = MySQLdb.connect('10.131.252.156', 'root', 'root', 'fdroid')
cursor = conn.cursor()
sql = '''SELECT gitcommit.commit_id,gitcommit.commit_date,gitcommit.repository_id,change_line.file_name,
change_line.line_number,change_line.content 
FROM fdroid.gitcommit inner join fdroid.change_line on gitcommit.commit_id = change_line.commit_id 
where change_line.repository_id = 828 and gitcommit.commit_date>'2016-12-27 09:41:50' 
and gitcommit.commit_date<'2016-12-29 17:46:06' order by commit_date'''
cursor.execute(sql)

path = r'C:\Users\fwk\Desktop\data'
filename = 'change_line_new.txt'
f = file(os.path.join(path, filename), 'w')
for line in cursor.fetchall():
    f.write(str(line)+'\n')
f.close()
cursor.close()
conn.close()
print 'ok'